import React, { useEffect, useState } from 'react';
import {
  Button,
  Cascader,
  DatePicker,
  Form,
  Input,
  InputNumber,
  Radio,
  Select,
  Switch,
  TreeSelect,
} from 'antd';
import {async_addshezhi,async_updateshezhi} from '../../store/crmslice'
import dayjs from 'dayjs';
import { useDispatch } from 'react-redux';
const Addlist = (props) => {
    let dispatch=useDispatch()
    const [form] = Form.useForm();
useEffect(()=>{
    form.setFieldsValue(props.update)
})

    const onFinish = values => {
       if(props.title=='添加'){
        let obj={
            ...values,
            time:dayjs().format("YYYY-MM-DD HH:mm:ss"),
            id:new Date().getTime()
        }
        dispatch(async_addshezhi(obj))
       }else{
        let obj={
            ...values,
            time:dayjs().format("YYYY-MM-DD HH:mm:ss"),
            id:props.update.id
        }
        dispatch(async_updateshezhi(obj))
       }
       props.onCancel()
      };

  return (
    <Form
    onFinish={onFinish}
    form={form}
    >
    <Form.Item label="参数主键" name="zhujian" 
       placeholder="请输入参数主键"
      rules={[{ required: true, message: '请输入参数主键!' }]}>
        <Input />
      </Form.Item>
      <Form.Item label="参数名称" name="name" 
       placeholder="请输入参数名称"
      rules={[{ required: true, message: '请输入参数名称!' }]}>
        <Input />
      </Form.Item>
      <Form.Item label="参数键名" name="jianming" 
       placeholder="请输入参数键名"
      rules={[{ required: true, message: '请输入参数键名!' }]}>
        <Input />
      </Form.Item>
      <Form.Item label="参数键值" name="jianzhi" 
       placeholder="请输入参数键值"
      rules={[{ required: true, message: '请输入参数键值!' }]}>
        <Input />
      </Form.Item>
      
      <Form.Item label="系统内置" name='neizhi'>
      <Radio.Group
    options={[
      { value: true, label: '是' },
      { value: false, label: '否' },
    ]}
  />
      </Form.Item>
      <Form.Item label="备注" name="beizhu"  placeholder="请输入内容">
        <Input />
      </Form.Item>
      <Form.Item>
        <Button htmlType="submit">完成</Button>
      </Form.Item>
    </Form>
  );
};
export default Addlist;